<?php
/**
 * @Author: lianlianzan(13040@qq.com)
 * @Date:   2018-08-18 16:40:16
 * @Last Modified by:   lianlianzan
 * @Last Modified time: 2020-11-07 12:44:49
 */

namespace app\admin\controller;
use app\common\controller\Backend;

class Index extends Backend {

	function initialize() {
		parent::initialize();
		$this->saveAndGetConfigIdentify('', '管理首页', '', '');
	}

	/**
	 * 首页
	 * @return [type] [description]
	 */
	public function index() {
		//$this->pageInfo('管理首页', 'home');

		//$indexMenu = logic('index')->getManageMenu($this->groupid);
		//print_r($indexMenu);
		//$this->assign("indexMenu", $indexMenu);
		
		if (config('dashboard_page')) {
			$this->redirect(url(config('dashboard_page')));
		}
		
		return $this->fetch();
	}

	/**
	 * 清理缓存
	 * @return [type] [description]
	 */
	public function delCache() {
		//防止认证信息被清理
		$eacoo_identification = cache('eacoo_identification');
		header("Content-type: text/html; charset=utf-8");
		//清文件缓存
		$dirs = [ROOT_PATH.'runtime/'];
		@mkdir('runtime',0777,true);
		//清理缓存
		foreach($dirs as $dir) {
			rmdirs($dir);
		}
		//清理缓存
		//logic('index')->clearCache();
		//防止认证信息被清理
		//cache('eacoo_identification',$eacoo_identification);
		$this->success('清除缓存成功！');
	}

	/**
	 * 优酷视频授权(这种刷新方法似乎废弃了)
	 */
// 	public function authorize() {
// 		$callback = 'http://'.$_SERVER['HTTP_HOST'].'/admin/index/authorize';
// 		
// 		/*****YoukuUpload SDK*****/
// 		header('Content-type: text/html; charset=utf-8');
// 		include(EXTEND_PATH."YoukuUploadSDK/include/YoukuUploader.class.php");
// 		
// 		$client_id = config('youku_id'); // Youku cloud client_id
// 		$client_secret = config('youku_secret'); //Youku cloud client_secret
// 		
// 		set_time_limit(0);
// 		ini_set('memory_limit', '128M');
// 		$youkuUploader = new \YoukuUploader($client_id, $client_secret);
// 		
// 		//获取openid
// 		$json = $youkuUploader->getOauthAccessToken($callback);
// 		$user_access_token = $json->access_token;
// 		
// 		if (empty($user_access_token)) {
// 			$url = $youkuUploader->getOauthRedirect($callback, 'xyz');
// 			//print_r($url);exit;
// 		    header("Location:".$url);exit;
// 		}
// 		
// 		//写入access_token
// 		$youkuDao = model('common/Youku');
// 		$refreshInfo = json_encode($json);
// 		$data = [
// 			'refresh_info'	=> $refreshInfo,
// 			'update_time'	=> $this->ts,
// 		];
// 		$youkuDao->baseUpdateData(1, $data);
// 	}
	
	//http://www2.kszhuangxiu.com/admin/index/getVideoInfo
	public function getVideoInfo() {
		$videoId = 'XNDA4NTMxMDUxNg==';
	
		/*****YoukuUpload SDK*****/
		header('Content-type: text/html; charset=utf-8');
		include(EXTEND_PATH."YoukuUploadSDK/include/YoukuUploader.class.php");
		
		$client_id = config('youku_id'); // Youku cloud client_id
		$client_secret = config('youku_secret'); //Youku cloud client_secret
		
		set_time_limit(0);
		ini_set('memory_limit', '128M');
		$youkuUploader = new \YoukuUploader($client_id, $client_secret);

		//获取上传视频信息
		$videoInfo = $youkuUploader->getVideoInfo($videoId);
		print_r($videoInfo);exit;
	}
}